/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.model.SetuBill;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class SetuBillListForCompExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"SetuBillListForComp.xls\"");
		HSSFSheet sheet = workbook.createSheet("list");
		List list = (List) model.get("list");
		HSSFRow r = sheet.createRow(0);
		HSSFCell c = r.createCell(0);
		r.createCell(1);
		r.createCell(2);
		r.createCell(3);
		r.createCell(4);
		r.createCell(5);
		r.createCell(6);
		r.createCell(7);
		r.createCell(8);
		r.createCell(9);
		c.setCellValue(new HSSFRichTextString("安装单完工"));
		sheet.addMergedRegion(new Region(0, 0, 0, 9));
		r = sheet.createRow(1);
		r.createCell(0).setCellValue(new HSSFRichTextString("单号"));
		r.createCell(1).setCellValue(new HSSFRichTextString("派单日期"));
		r.createCell(2).setCellValue(new HSSFRichTextString("订货单位"));
		r.createCell(3).setCellValue(new HSSFRichTextString("业务单号"));
		r.createCell(4).setCellValue(new HSSFRichTextString("业务摘要"));
		r.createCell(5).setCellValue(new HSSFRichTextString("金额"));
		r.createCell(6).setCellValue(new HSSFRichTextString("计划完工"));
		r.createCell(7).setCellValue(new HSSFRichTextString("安装人员"));
		r.createCell(8).setCellValue(new HSSFRichTextString("负责人"));
		r.createCell(9).setCellValue(new HSSFRichTextString("开单人"));
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

		for (int os = 0; os < list.size(); ++os) {
			Object[] objs = (Object[]) list.get(os);
			SetuBill b = (SetuBill) objs[0];
			String billDateStr = sf.format(b.getBillDate());
			String planDateStr = sf.format(b.getPlanDate());
			r = sheet.createRow(os + 2);
			r.createCell(0).setCellValue(
					new HSSFRichTextString(b.getBillCode()));
			r.createCell(1).setCellValue(new HSSFRichTextString(billDateStr));
			r.createCell(2).setCellValue(
					new HSSFRichTextString((String) objs[1]));
			r.createCell(3).setCellValue(
					new HSSFRichTextString((String) objs[2]));
			r.createCell(4).setCellValue(
					new HSSFRichTextString((String) objs[3]));
			r.createCell(5).setCellValue(b.getCost().doubleValue());
			r.createCell(6).setCellValue(new HSSFRichTextString(planDateStr));
			r.createCell(7).setCellValue(
					new HSSFRichTextString(b.getSetuNameStr()));
			r.createCell(8)
					.setCellValue(new HSSFRichTextString(b.getMngName()));
			r.createCell(9).setCellValue(
					new HSSFRichTextString(b.getCreaName()));
		}

		ServletOutputStream arg14 = response.getOutputStream();
		workbook.write(arg14);
		arg14.flush();
		arg14.close();
	}
}